home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWMenu / Include / FWMnuBar.h < prev    next >
Encoding:
Text File  |  1995-11-08  |  8.8 KB  |  288 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWMnuBar.h
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1993, 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWMNUBAR_H
  11. #define FWMNUBAR_H
  12.  
  13. #ifndef FWCOMMON_H
  14. #include "FWCommon.h"
  15. #endif
  16.  
  17. #ifndef FWDEBUG_H
  18. #include "FWDebug.h"
  19. #endif
  20.  
  21. // ----- OpenDoc Includes -----
  22.  
  23. #ifndef SOM_ODMenuBar_xh
  24. #include <MenuBar.xh>
  25. #endif
  26.  
  27. // ----- Platform Includes -----
  28.  
  29. #if defined(FW_BUILD_WIN) && !defined(_INC_WINDOWS)
  30. #include <windows.h>
  31. #endif
  32.  
  33. #if FW_LIB_EXPORT_PRAGMAS
  34. #pragma lib_export on
  35. #endif
  36.  
  37. //========================================================================================
  38. //    Forward class definitions
  39. //========================================================================================
  40.  
  41. class FW_CLASS_ATTR ODPart;
  42. class FW_CLASS_ATTR FW_CPullDownMenu;
  43. class FW_CLASS_ATTR FW_CPrivOrderedCollection;
  44. class FW_CLASS_ATTR FW_CString;
  45. class FW_CLASS_ATTR FW_CMenuItem;
  46.  
  47. //========================================================================================
  48. //    Defines
  49. //========================================================================================
  50.  
  51. typedef short FW_MenuKey;
  52. const FW_MenuKey FW_kNoKeyEquivalent = 0;
  53. const FW_MenuKey FW_kMenuKeyCharMask = 0x00FF;
  54.  
  55. #ifdef FW_BUILD_MAC
  56. const short FW_kScriptCodeKeyEquivalent = 28;    // key equiv value of $1C indicates that the icon field contains a script code
  57. #endif
  58.  
  59. const ODMenuID FW_kFirstMenuID = 4;
  60.  
  61. //========================================================================================
  62. //    class FW_CMenuBar
  63. //========================================================================================
  64.  
  65. class FW_CLASS_ATTR FW_CMenuBar
  66. {
  67. //----------------------------------------------------------------------------------------
  68. //    Constructors/Destructors
  69. //
  70. public:
  71.     FW_CMenuBar(Environment* ev, ODPart* thePart);
  72.     virtual ~FW_CMenuBar();
  73.     
  74. //----------------------------------------------------------------------------------------
  75. //    New API
  76. //
  77. public:
  78.     // ----- Adding -----
  79.     void                 AdoptMenuFirst(Environment* ev, 
  80.                             FW_CPullDownMenu* menu);
  81.     void                 AdoptMenuLast(Environment* ev, 
  82.                             FW_CPullDownMenu* menu);
  83.                             
  84.     void                 AdoptMenuBefore(Environment* ev, 
  85.                             FW_CPullDownMenu* menu, 
  86.                             FW_CPullDownMenu* beforeMenu);    // if beforeMenu == NULL -> AdoptMenuFirst
  87.     void                 AdoptMenuAfter(Environment* ev, 
  88.                             FW_CPullDownMenu* menu, 
  89.                             FW_CPullDownMenu* afterMenu);    // if afterMenu == NULL -> AdoptMenuLast
  90.  
  91.     // ----- Removing/Detaching -----
  92.     void                 DetachMenu(Environment* ev, 
  93.                             FW_CPullDownMenu* menuToDetach);    
  94.     void                 DeleteMenu(Environment* ev, 
  95.                             FW_CPullDownMenu* menuToDelete);    // DetachMenu + delete of the menu
  96.     void                 DeleteAll(Environment* ev);
  97.  
  98.     void                RemoveItem(Environment* ev, ODCommandID commandID);
  99.     
  100.     // ----- Item access -----
  101.     void                 SetItemString(Environment* ev,
  102.                             ODCommandID commandID, 
  103.                             const FW_CString& itemString);
  104.     void                 GetItemString(Environment* ev, 
  105.                             ODCommandID commandID, 
  106.                             FW_CString& itemString) const;
  107.     
  108.     void                 EnableCommand(Environment* ev, 
  109.                             ODCommandID cmdNumber, 
  110.                             FW_Boolean enable);
  111.     void                 CheckCommand(Environment* ev, 
  112.                             ODCommandID cmdNumber, 
  113.                             FW_Boolean check);
  114.     void                 ToggleItem(Environment* ev, 
  115.                             ODCommandID cmdNumber, 
  116.                             FW_Boolean toggleState);
  117.                             
  118.     void                 EnableAndCheckCommand(Environment* ev, 
  119.                             ODCommandID cmdNumber, 
  120.                             FW_Boolean enable,
  121.                             FW_Boolean check);
  122.     void                 EnableAndToggleCommand(Environment* ev, 
  123.                             ODCommandID cmdNumber, 
  124.                             FW_Boolean enable,
  125.                             FW_Boolean toggleState);
  126.  
  127.     FW_MenuKey            GetMenuKey(Environment* ev,
  128.                             ODCommandID cmdNumber) const;
  129.                         
  130.     void                DisableAll(Environment* ev);
  131.     void                EnableAll(Environment* ev);
  132.     
  133.     // ----- Getters/Setters -----    
  134.     FW_CMenuItem*        GetMenuItemFromCommand(Environment* ev, 
  135.                             ODCommandID cmdNumber) const;
  136.                                 
  137.     ODMenuBar*            AcquireODMenuBar(Environment* ev) const;
  138.     ODPart*                GetODPart(Environment* ev) const;
  139.     
  140.  
  141. //----------------------------------------------------------------------------------------
  142. //    Internal API
  143. //
  144. public:
  145.     void                 PrivDisplay(Environment* ev);    
  146.     
  147.     FW_CPullDownMenu*     PrivFindMenuWithID(Environment* ev, 
  148.                             ODMenuID menu) const;
  149.         
  150.     ODMenuID            PrivGetNewMenuID(Environment* ev);
  151.  
  152. #ifdef FW_BUILD_MAC
  153.     void                PrivMacEnableParentItem(Environment* ev, 
  154.                             ODCommandID cmdNumber);
  155.     
  156.     void                PrivMacRegisterCommand(Environment* ev,
  157.                             ODCommandID commandID,
  158.                             ODMenuID menuID,
  159.                             short itemID);
  160.     void                PrivMacUnregisterCommand(Environment* ev,
  161.                             ODCommandID commandID);
  162.     ODCommandID            PrivMacGetCommand(Environment* ev,
  163.                             ODMenuID menuID,
  164.                             short itemID);
  165.     
  166. #endif
  167.  
  168.     void                PrivAddSubMenu(Environment* ev,
  169.                             short subMenuID,
  170.                             ODPlatformMenu platformMenu);
  171.     void                PrivRemoveMenu(Environment* ev, 
  172.                                         short menuID);
  173.                             
  174. //----------------------------------------------------------------------------------------
  175. //    Platform specific API
  176. //
  177. #ifdef FW_BUILD_MAC
  178. public:
  179.     // ----- Enable/Disable of the whole menuBar -----
  180.     void                MacEnableMenuBar(Environment* ev, 
  181.                             FW_Boolean enable);
  182. #endif
  183.                         
  184. //----------------------------------------------------------------------------------------
  185. //    Data Members
  186. //
  187. private:
  188.     ODMenuBar*                    fODMenuBar;
  189.     ODPart*                        fODPart;
  190.     FW_CPrivOrderedCollection*    fPullDownMenuList;
  191.     ODMenuID                    fNextMenuID;            
  192. };
  193.  
  194. //========================================================================================
  195. //    FW_CMenuBar inlines
  196. //========================================================================================
  197.  
  198. //----------------------------------------------------------------------------------------
  199. //    FW_CMenuBar::PrivDisplay
  200. //----------------------------------------------------------------------------------------
  201. inline void FW_CMenuBar::PrivDisplay(Environment* ev)
  202. {
  203.     fODMenuBar->Display(ev);
  204. }
  205.  
  206. //----------------------------------------------------------------------------------------
  207. //    FW_CMenuBar::GetODPart
  208. //----------------------------------------------------------------------------------------
  209. inline ODPart* FW_CMenuBar::GetODPart(Environment* ev) const
  210. {
  211.     return fODPart;
  212. }
  213.  
  214. //----------------------------------------------------------------------------------------
  215. //    FW_CMenuBar::PrivGetNewMenuID
  216. //----------------------------------------------------------------------------------------
  217. inline ODMenuID FW_CMenuBar::PrivGetNewMenuID(Environment* ev)
  218. {
  219.     FW_ASSERT(fNextMenuID < 255);
  220.     return fNextMenuID++;
  221. }
  222.  
  223. #ifdef FW_BUILD_MAC
  224. //----------------------------------------------------------------------------------------
  225. //    FW_CMenuBar::PrivMacRegisterCommand
  226. //----------------------------------------------------------------------------------------
  227. inline void FW_CMenuBar::PrivMacRegisterCommand(Environment* ev,
  228.                                                 ODCommandID commandID,
  229.                                                 ODMenuID menuID,
  230.                                                 short itemID)
  231. {
  232.     fODMenuBar->RegisterCommand(ev, commandID, menuID, itemID);
  233. }
  234. #endif
  235.  
  236. #ifdef FW_BUILD_MAC
  237. //----------------------------------------------------------------------------------------
  238. //    FW_CMenuBar::PrivMacUnregisterCommand
  239. //----------------------------------------------------------------------------------------
  240. inline void FW_CMenuBar::PrivMacUnregisterCommand(Environment* ev,
  241.                                                 ODCommandID commandID)
  242. {
  243.     fODMenuBar->UnregisterCommand(ev, commandID);
  244. }
  245. #endif
  246.     
  247. #ifdef FW_BUILD_MAC
  248. //----------------------------------------------------------------------------------------
  249. //    FW_CMenuBar::PrivMacGetCommand
  250. //----------------------------------------------------------------------------------------
  251. inline ODCommandID FW_CMenuBar::PrivMacGetCommand(Environment* ev,
  252.                                                 ODMenuID menuID,
  253.                                                 short itemID)
  254. {
  255.     return fODMenuBar->GetCommand(ev, menuID, itemID);
  256. }
  257. #endif
  258.     
  259. //----------------------------------------------------------------------------------------
  260. //    FW_CMenuBar::PrivAddSubMenu
  261. //----------------------------------------------------------------------------------------
  262. inline void FW_CMenuBar::PrivAddSubMenu(Environment* ev,
  263.                                         short subMenuID,
  264.                                         ODPlatformMenu platformMenu)
  265. {
  266. #ifdef FW_BUILD_MAC
  267.     fODMenuBar->AddSubMenu(ev, subMenuID, platformMenu, fODPart);
  268. #endif
  269. #ifdef FW_BUILD_WIN
  270.     // [WIN_PORT] AddSubMenu is missing in OpenDoc/Win!
  271. #endif
  272. }
  273.  
  274. //----------------------------------------------------------------------------------------
  275. //    FW_CMenuBar::PrivAddSubMenu
  276. //----------------------------------------------------------------------------------------
  277. inline void FW_CMenuBar::PrivRemoveMenu(Environment* ev, 
  278.                                         short menuID)
  279. {
  280.     fODMenuBar->RemoveMenu(ev, menuID);
  281. }
  282.  
  283. #if FW_LIB_EXPORT_PRAGMAS
  284. #pragma lib_export off
  285. #endif
  286.  
  287. #endif
  288.